<?php

/**
 * Created by EPP.
 * User: yuxun
 * Date: 18/6/26
 * Time: 21:21
 */
class PacketNumController extends AdminBaseController {

    public function index(){
        $this->setTitle('包号管理');

        $filter = new PubFilter();
        $grid   = new PubGrid();

        $filter->addOssChannel(true);
        $filter->addFilter('number', 'input', '编号');
           
        $params = $filter->get();
        $header = PacketNumService::indexHeader();
        $data   = PacketNumService::indexData($params);
        
        $grid->addGrid($header, $data);

        $this->out['filter'] = $filter->show();
        $this->out['grid'] = $grid->show();
        
    }

    public function add(){
        $this->setTitle('新建包号');       
        $channelList = PubServer::getPacketOptions($game, 'id');        
        $this->out['channelList'] = $channelList;
    }

    public function doAdd(){
        $result = PacketNumService::doAdd($_POST);

        if($result !== false){
            $this->showMessage('新增成功', PubFunc::buildUrl("/oss/?r=packetNum/index"));
        }else{
            $this->showMessage('新增失败');
        }
    }

    public function edit(){
        $id = $this->R('id');
        $info = PacketNumService::get($id);

        if(empty($info)) $this->showMessage('找不到该信息');

        $this->setTitle('编辑渠道', $info['number']);

        $this->out['info'] = $info;
        
        $channelList = PubServer::getPacketOptions($game, 'id');
        $this->out['channelList'] = $channelList;
    }

    public function doEdit(){
        $id = $this->R('id');
        $result = PacketNumService::doEdit($id, $_POST);

        if($result !== false){
            $this->showMessage('编辑成功', PubFunc::buildUrl("/oss/?r=packetNum/index"));
        }else{
            $this->showMessage('编辑失败');
        }
    }

    public function delete(){
        $id = $this->R('id');

        $result = PacketNumService::delete($id);

        if($result !== false){
            $this->showMessage('删除成功', PubFunc::buildUrl("/oss/?r=packetNum/index"));
        }else{
            $this->showMessage('删除失败');
        }
    }

}